package com.esisa.java.swing;

import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class LabeledTextField extends JPanel {
	private JLabel label;
	private JTextField textField;
	
	public LabeledTextField(String label, int size) {
		setLayout(new FlowLayout(FlowLayout.LEFT));
		if (!label.contains(":")) label = label + " : ";
		this.label = new JLabel(label);
		this.textField = new JTextField(size);
		add(this.label);
		add(textField);
	}

	public LabeledTextField(String label, int size, int labelWidth) {
		this(label, size);
		this.label.setPreferredSize(new Dimension(labelWidth, 20));
	}

	public void setValue(String value) { 
		textField.setText(value);
	}
	
	public String getValue() {
		return textField.getText();
	}
	
}
